﻿#region
/*******************************************************************************
** File Name:		    AdminGroupService.cs
** Creator:		        chao.jiang 
** EMail:               chao.jiang 
** Create date:	        
** Latest Modifier:
** Latest Modify date:
** Description:		    
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using Phoenix.Service.Contracts;
using Phoenix.Service.Model;
using Phoenix.IBatisRepository;
using Phoenix.Respository;
using System.Data;
using Phoenix.Entity;

namespace Phoenix.Service
{
    public class AdminGroupService : IAdminGroupService
    {
        IAdminGroup adminGroup = new AdminGroupRepository();

        #region  Auto Generation

        public void AddAdminGroup(AdminGroupModel model)
        {
            EAdminGroup entity = ConvertModelToEntity(model);

            adminGroup.AddAdminGroup(entity);
        }

        public void UpdateByGroupID(AdminGroupModel model)
        {
            EAdminGroup entity = ConvertModelToEntity(model);

            adminGroup.UpdateByGroupID(entity);

        }

        public void DeleteByGroupID(System.Int32 groupID)
        {

            adminGroup.DeleteByGroupID(groupID);

        }

        public AdminGroupModel GetByGroupID(System.Int32 groupID)
        {

            EAdminGroup entity = adminGroup.GetByGroupID(groupID);

            AdminGroupModel model = ConvertEntityToModel(entity);


            return model;
        }

        public AdminGroupModel ConvertEntityToModel(EAdminGroup entity)
        {
            if (entity == null)
            {
                return null;
            }
            AdminGroupModel model = new AdminGroupModel();
            model.GroupID = entity.GroupID;
            model.GroupName = entity.GroupName;
            model.Memo = entity.Memo;
            model.OrgID = entity.OrgID;
            return model;
        }

        public EAdminGroup ConvertModelToEntity(AdminGroupModel model)
        {
            if (model == null)
            {
                return null;
            }
            EAdminGroup entity = new EAdminGroup();
            entity.GroupID = model.GroupID;
            entity.GroupName = model.GroupName;
            entity.Memo = model.Memo;
            entity.OrgID = model.OrgID;
            return entity;
        }

        #endregion

        public IList<AdminGroupModel> GetByOrgID(int orgID)
        {
            IList<EAdminGroup> entityList = adminGroup.GetByOrgID(orgID);

            if (entityList == null)
                return null;
            IList<AdminGroupModel> modelList = new List<AdminGroupModel>();

            foreach (var item in entityList)
            {
                modelList.Add(ConvertEntityToModel(item));
            }
            return modelList;
        }
    }
}